package sicau.practice.community.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import sicau.practice.community.Mapper.TieziMapper;
import sicau.practice.community.dto.Tiezi;

@Controller
public class PublishController {
    
    @Autowired
    TieziMapper tieziMapper;
    
    @GetMapping("/publish")
    public String publish(){
        return "publish";
    }

    @PostMapping("/publish")
    public String doPublish(
            @RequestParam("title") String title,
            @RequestParam("description") String description,
            @RequestParam("tag") String tag
    ){
        Tiezi tiezi = new Tiezi();
        tiezi.setTitle(title);
        tiezi.setDescription(description);
        tiezi.setTag(tag);
        tieziMapper.create(tiezi);
        System.out.println("已添加");

        return "redirect:/";
    }
}
